<?php
/**
 * <https://y.st./>
 * Copyright © 2018 Alex Yst <mailto:copyright@y.st>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org./licenses/>.
**/

$xhtml = array(
	'<{title}>' => 'Hack',
	'takedown' => '2017-11-01',
	'<{body}>' => <<<END
<section id="PHP">
	<h2>$a[PHP] and Hack</h2>
	<p>
		I was trying to do research on the Hack platform to aid in the completion of my coursework this week.
		Instead of finding anything useful to my studies, I discovered a language that shares its name with the simple computer.
		This language seems to be in development by Facebook, the evil social media platform, based on my native tongue, $a[PHP].
		Needless to say, I got distracted for a bit researching this language.
		From what I can tell, the language includes the core feature I demand from $a[PHP]; that is, its hybrid procedural/$a[OOP] setup that allows classes, functions, and constants to be more than just objects.
		Yes; that&apos;s right; I love $a[PHP] because it&apos;s mashup language that isn&apos;t fully procedural and not fully object-oriented.
		Anyway, there would be no particular reason for Facebook to remove this, and it&apos;s pretty deeply embedded in the syntax of the language.
		On top of that, Hack boasts several cool features over $a[PHP] ... except that $a[PHP] actually has some of those features.
		My best guess is that Facebook jumped the gun and implemented those before the $a[PHP] team did, added them to the improved feature list, then didn&apos;t update the improved feature list when the $a[PHP] team caught up.
	</p>
	<p>
		That aside, Hack does have some nice features over $a[PHP], and I&apos;d consider switching if not for the hassle.
		For example, Hack allows generic typing and forced type specifications.
		The source code is publicly available under free licenses: the $a[PHP] license, the Zend license, and the $a[BSD] license.
		However ... Hack isn&apos;t in Debian Stable&apos;s repo.
		I have too much on my plate to be dealing with third-party software as the main language I write everything in.
		It looks like Hack (or rather, $a[HHVM], the engine for running Hack code) is in the Debian Unstable repository.
		There&apos;s an almost-definite chance I&apos;ll at least give Hack a try, once it reaches the stable version of Debian.
		Some of the features in Hack aren&apos;t well-implemented though.
		For example, certain comments are treated not as comments, but actual language constructs.
		Still, overall, I think Hack might be a better dialect of the language.
	</p>
</section>
<section id="university">
	<h2>University drudgery</h2>
	<p>
		My discussion post for the day was as follows:
	</p>
	<blockquote>
		<p>
			I think symbols can only be used in A instructions.
			They&apos;re used to refer to specific numbers to be entered via the A register.
			These numbers are typically the memory addresses of data (in the case of variables) or instructions (in the case of labels), though it&apos;s technically true that arbitrary numbers could also be given a symbol as well via some slight trickery.
			However, symbols have nothing to do with C-instructions, and the assembler is perfectly capable of telling the difference between A-instructions and C-instructions without a two-pass process or a symbol table.
			The only good the two-pass system and the symbol table do is in interpreting A-commands that use symbols.
			A symbol itself only represents a value, and while it&apos;s used in A-commands, it cannot itself <strong>*be*</strong> an A-command or a C-command.
		</p>
		<p>
			Additionally, the variables are created during the second pass.
			Only the labels are found in the first pass.
			Variables are simply assigned an address as they need one.
			That means that unknown variables wouldn&apos;t cause a crash in the assembler; only unknown labels would.
		</p>
		<p>
			The benefit of a two-pass assembler is that it takes less memory.
			In a one-pass assembler, the entire assembled code must be held in memory at once.
			This is because the binary can&apos;t be written to the file until it is complete, as it&apos;ll still need to be modified by patching in the addresses as their labels are found.
			In fact, a symbol cannot be determined to be a variable or a label until all the labels are found, which means that in addition to forward-jumping labels, <strong>*all*</strong> variables must be backpatched.
			For small programs, this is no big deal, but for larger programs, it can eat up too much memory.
			Program size is therefore more limited when working with backpatching.
		</p>
	</blockquote>
</section>
<section id="include.d">
	<h2>include.d version 0.0.1.8.0.0.0.1</h2>
	<p>
		I found another issue with the assembler that needs to be fixed.
		In the discussion today, I realised I&apos;d completely negated the benefits of a two-pass assembler in my design when I refactored it.
		Namely, a two-pass assembler doesn&apos;t have to store the whole assembled program in program in memory at once.
		Mine does it anyway though, so it has the high memory consumption of a one-pass assembler and the low speed of a two-pass assembler.
		I&apos;ve now fixed that, though I&apos;ve had to alter the $a[API] a bit in the process.
		The new wrapper script is as follows:
	</p>
	<blockquote>
<pre><code>&lt;?php declare(strict_types=1);
/**
 * Copyright © 2017-2018 Alex Yst &lt;mailto:copyright@y.st&gt;
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see &lt;http://www.gnu.org./licenses/&gt;.
**/

// Causes all errors to be terminal
require &apos;st/y/function/error_handler.php&apos;;
set_error_handler(&apos;\\\\st\\\\y\\\\error_handler&apos;);
// Sets the script up to used the classes from include.d
spl_autoload_register();
// Pulls in the function file
require &apos;st/y/function/hack_assemble.php&apos;;

// This is where all the magic happens.
foreach(\\st\\y\\hack_asseble(file_get_contents(\$argv[1])) as \$line):
	echo \$line;
endforeach;</code></pre>
	</blockquote>
</section>
<section id="health">
	<h2>Health watch</h2>
	<p>
		I&apos;m still physically ill, though I think I&apos;m almost better now.
		I&apos;m certainly absorbing more water than I have been able to over the past couple days.
	</p>
	<p>
		On an emotional level, I&apos;m also continuing to improve.
		I can only assume my infected tooth hypothesis was correct and that the infection had been souring my outlook on things.
		Tonight is the first time in a couple months I&apos;ve felt up to actually hanging my laundry after washing it.
		As a side note, a couple weeks ago, the price on that cheap washing machine went up to match the other two, so we&apos;re back to full price for laundry loads.
	</p>
</section>
END
);
